package org.liaohailong.victorlibrary.ui

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.widget.MediaController
import android.widget.VideoView
import kotlinx.android.synthetic.main.activity_video.*
import org.liaohailong.victorlibrary.R
import org.liaohailong.victorlibrary.base.BaseActivity

/**
 * Author: liaohailong
 * Date: 2019/4/15
 * Time: 2:56 PM
 * Description:
 **/
class VideoActivity : BaseActivity() {
    companion object {
        fun show(context: Context) {
            val intent = Intent(context, VideoActivity::class.java)
            context.startActivity(intent)
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_video)

        play(video_view1, "https://cdn.api.wanzi.cn/videos/interact/2019-04-15/users/276/1555297210047_ld.mp4")
//        play(video_view2, "https://dev-cdn.api.wanzi.cn/debug/test/3.mp4")
    }

    private fun play(videoView: VideoView, url: String) {
        videoView.setVideoPath(url)
        videoView.setMediaController(MediaController(this))
        videoView.setOnPreparedListener { videoView.start() }
        videoView.setOnCompletionListener { videoView.start() }
    }
}